/**
 * Copyright 2010 The original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.as3commons.collections.framework.core {
import org.as3commons.collections.framework.IDuplicates;

/**
	 * Abstract linked list based collection implementation with permission of duplicates.
	 * 
	 * @author Jens Struwe 12.04.2010
	 */
	public class AbstractLinkedDuplicatesCollection extends AbstractLinkedCollection implements IDuplicates {

		/**
		 * @inheritDoc
		 */
		public function count(item : *) : uint {
			var count : uint = 0;
			var node : LinkedNode = _first;
			while (node) {
				if (node.item === item) count++;
				node = node.right;
			}
			return count;
		}
		
		/**
		 * @inheritDoc
		 */
		public function removeAll(item : *) : uint {
			var size : uint = _size;
			var node : LinkedNode = _first;
			var right : LinkedNode;
			while (node) {
				right = node.right;
				if (node.item === item) {
					removeNode(node);
				}
				node = right;
			}
			return size - _size;
		}
		
	}
}
